package com.bzchao.oauth.service.impl;

import com.bzchao.oauth.bean.SysUser;
import com.bzchao.oauth.bean.SysUserExample;
import com.bzchao.oauth.mapper.SysUserMapper;
import com.bzchao.oauth.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SysUserServiceImpl implements UserService {
    @Autowired
    private SysUserMapper dao;

    @Override
    public boolean add(SysUser user) {
        dao.insert(user);
        return true;
    }

    @Override
    public boolean update(SysUser user) {
        dao.updateByPrimaryKey(user);
        return true;
    }

    @Override
    public SysUser get(String uuid) {
        return dao.selectByPrimaryKey(uuid);
    }

    @Override
    public List<SysUser> list() {
        return dao.selectByExample(new SysUserExample());
    }

    @Override
    public SysUser findByUsername(String username) {
        SysUserExample userExample = new SysUserExample();
        userExample.createCriteria().andUserNameEqualTo(username);
        List<SysUser> sysUsers = dao.selectByExample(userExample);
        if (sysUsers == null || sysUsers.size() == 0) {
            return null;
        }
        return sysUsers.get(0);
    }

}
